<template>
	<view class="tab_bar">
		<view class="tabbarBox">
			<view class="handleBox" v-for="(item,index) in tabBarList" :key="index">
				<view class="menuBox" @click="goPages(item.pageIndex)" >
								
					<view class="menuIcon" style="position: relative;">
						<image v-if="item.pageIndex!=selectIndex" class="img"  :src="item.iconPath"></image>
						<image v-else class="img":src="item.selectIconPath"></image>
						 <u-badge max="99" absolute :offset="offset" v-if="item.pageIndex=='/pages/msg/index'"  shape="circle" :value="num"></u-badge>
					</view>
					<view class="menuName">
						<view :class="item.pageIndex==selectIndex?'TextColor':'Text'">{{item.tabbarName}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			page: {
				type: String,
				default: "/pages/index/index"
			}
		},
		watch: {
			page: {
				handler(value) {
					this.selectIndex = value;
				},
				immediate: true,
				deep: true,
			}
			
		},
		data() {
			return {
				selectIndex: "",
				num:0,
				offset:[-10,-8],
				tabBarList:  [
				{
					"tabbarName": "首页", //tababr名称
					"iconPath": "https://yun.iyunqiye.cn/upload/admin/home.png", //tabbar icon
					"selectIconPath": "https://yun.iyunqiye.cn/upload/admin/home1.png", //tabbar 选择icon
					"pageIndex": "/pages/index/index" //页面路径
				},
				{
					"tabbarName": "我的", //tababr名称
					"iconPath": "https://yun.iyunqiye.cn/upload/admin/my.png", //tabbar icon
					"selectIconPath": "https://yun.iyunqiye.cn/upload/admin/my1.png", //tabbar 选择icon
					"pageIndex": "/pages/my/index" //页面路径
				},
			],
			}

		},
		//uniapp子组件不支持应用生命周期，所以只能用vue生命周期
		created() {
			//tabbar数据，这儿也支持后台定义通过接口获取数据
			// this.tabBarList =[]
				// this.get_count();
		},
		methods: {
			//进入tabble页
			goPages(pageIndex) {
				// this.get_count();
				console.log(pageIndex,'xuanz')
				uni.switchTab({
					url: pageIndex
				})
			},
			// get_count() {
			// 	let data = {}
			// 	data.openid = uni.getStorageSync('openid')
			// 	this.$request.request({
			// 		url: 'api/ser/index/get_wx_msg',
			// 		data: data,
			// 	}).then(res => {
			// 		this.num = Number(res.data)
			// 	})
			// },
		},
	}
</script>
<style lang="scss">
	.tab_bar {
		width: 100vw;
		height: calc(60px + env(safe-area-inset-bottom));
		position: fixed;
		bottom: 0px;
		background-color: #fff;
		.tabbarBox {
			display: flex;
			margin-top: 5px;
			justify-content: space-evenly;
			.handleBox {
				width: 20vw;
				height: 60px;
				.menuBox {
					padding: 7px 10px 10px 10px;
					width: 60px;
					text-align: center;
				}
			}
		}
	}

	.Text {
		font-size: 12px;
		font-weight: 500;
		line-height: 16px;
	}
	.menuIcon{
		height: 22px;
		width: 22px;
		// background-color: #f00;
		margin-left: 20px;
	}
	.menuName{
		margin-top: 5px;
		// background-color: #fff;
	}
	.img {
		height: 22px;
		width: 22px;
	}
	.TextColor {
		@extend .Text;
		color: #408fff;
	}
</style>